package com.whw.springboot.walk.service.servicelmpl;

import cn.hutool.poi.excel.ExcelReader;
import cn.hutool.poi.excel.ExcelUtil;
import com.sun.rowset.internal.Row;
import com.whw.springboot.walk.entity.Lesson;
import com.whw.springboot.walk.entity.LessonNumber;
import com.whw.springboot.walk.entity.Message;
import com.whw.springboot.walk.mapper.LessonMapper;
import com.whw.springboot.walk.service.LessonService;
import com.whw.springboot.walk.utils.LessonUtil;
import com.whw.springboot.walk.utils.MyException;

import org.springframework.stereotype.Service;
import org.springframework.web.multipart.MultipartFile;

import javax.annotation.Resource;
import java.io.InputStream;
import java.text.ParseException;
import java.util.ArrayList;
import java.util.List;

@Service
public class LessonServiceImpl implements LessonService {

    @Resource
    private LessonMapper lessonMapper;

    @Override
    public Message<?> addLesson(LessonNumber lessonNumber) throws ParseException {
        System.out.println(lessonNumber.toString());
        String lessonId = "LS"+LessonUtil.bianHao();
        lessonNumber.setLessonId(lessonId);
        return lessonMapper.addLesson(LessonUtil.change(lessonNumber)) > 0 ? Message.success(null) : Message.fail(null);
    }


    @Override
    public Message<?> deleteLessonByPrimaryKey(String lessonId){
        return lessonMapper.deleteLessonByPrimaryKey(lessonId)>0?Message.success(null):Message.fail(null);
    }

    @Override
    public Message<List<Lesson>> selectAllLessonName() {
        return Message.success(null).add(lessonMapper.selectAllLessonName());
    }


    @Override
    public Message<List<Lesson>> selectAllTeacher(){
        return Message.success(null).add(lessonMapper.selectAllTeacher());
    }


    @Override
    public Message<Lesson> selectTeacherByLessonName(String lessonName) {
        return Message.success(null).add(lessonMapper.selectTeacherByLessonName(lessonName));
    }


    @Override
    public Message<Lesson> selectLessonNameByTeacher(String lessonTeacher){
        return Message.success(null).add(lessonMapper.selectLessonNameByTeacher(lessonTeacher));
    }


    @Override
    public Message<?> updateLessonPersonNumByLessonName(LessonNumber lessonNumber){
        return lessonMapper.updateLessonPersonNumByLessonName(lessonNumber)> 0 ? Message.success(null) : Message.fail(null);
    }


    @Override
    public Message selectLessonByLessonId(String lessonId) {
        return Message.success(null).add(lessonMapper.selectLessonByLessonId(lessonId));
    }

    @Override
    public Message<?> updateLessonPersonNumByPK(String lessonId, String lessonPersonNum) {
        return null;
    }

    @Override
    public int importLesson(MultipartFile file) throws Exception {
        return 0;
    }


  /*  @Override
    public Message<?> updateLessonPersonNumByPK(String lessonId, String lessonPersonNum) {
        return lessonMapper.updateLessonPersonNumByPK(lessonId,lessonPersonNum)>0 ? Message.success(null) : Message.fail(null);
    }

        @Override
        public int importLesson(MultipartFile file) throws Exception{
            int result = 0;

            ExcelReader reader = ExcelUtil.getReader("d:/aaa.xlsx");
            List<Lesson> all = reader.readAll(Lesson.class);


        }
        */

    }
